<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <title>生猪贸易平台</title>
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="css/bui.css" />
</head>
<body>
<style type="text/css">

    .login-page main{
        background: #fff url(../images/login/login-bg.png) center bottom no-repeat;
        background-size: 100% auto;

    }
    .login-page .logo h1{
        font-size: .82rem;
        padding-left: .3rem;
    }
    .logo{
        height: 2rem;
        margin: 1.2rem auto 1rem auto;
        text-align: center;
    }
    .logo img{
        height: 1rem;
    }
    .login-form {
        padding-left: .6rem;
        padding-right: .6rem;
    }
    .login-form .bui-list{
        border-top: none;
        margin-bottom: .7rem;
    }
    .login-form > .bui-btn{
        margin-bottom: .3rem;
    }
    .login-form .bui-btn-text{
        margin-bottom: .2rem;
    }
    .bui-list>[class*=bui-btn]:last-child {
    }
    .login-form .bui-label{
        width: 0.5rem;
        margin-right: .2rem;
    }
    .login-form .icon-face,
    .login-form .icon-lock{
        font-size: 0.48rem;
    }
    .login-form .bui-input {
        height: .6rem;
        background: none;
    }
    .login-form .bui-btn-text{
        text-align: center;
        color: #666666;
        font-size: 0.2rem;
    }
    .copyright{
        font-size: 0.17rem;
        color: #999999;
        width: 100%;
        text-align: center;
        background-color: #ffffff;
        padding-bottom: 0.25rem;
    }

    .icon-eye:before {
        content: "\e680"
    }
    .icon-eye.active:before {
        content: "\e67f"
    }

</style>
<div class="bui-page login-page">
    <main>
        <div class="logo bui-box-center">
            <img src="images/pig.png" alt="" style="width: 1.5rem;height: 1.5rem">
        </div>
        <div class="bui-box-center" style="margin-top: -50px;margin-bottom: 20px">
            生猪贸易平台
        </div>

        <div class="login-form">
            <ul class="bui-list">
                <li class="bui-btn bui-box clearactive">
                    <label class="bui-label" for="phone"><i class="icon-face"></i></label>
                    <div class="span1">
                        <div class="bui-input user-input">
                            <input id="phone" type="text" placeholder="手机号">
                        </div>
                    </div>
                </li>
                <li class="bui-btn bui-box clearactive">
                    <label class="bui-label" for="code"><i class="icon-lock"></i></label>
                    <div class="span1">
                        <div class="bui-input password-input">
                            <input id="code" type="text" placeholder="验证码">
                        </div>

                    </div>
                    <div class="bui-btn primary-reverse mini ring" id="btnSend">发送验证码</div>
                </li>
            </ul>
            <div class="bui-btn round primary" id="login" href="">登录</div>
<!--            <div class="bui-btn-text" href="pages/register/register.html">注册</div>-->
<!--            <div class="bui-btn-text">忘记密码</div>-->
        </div>
    </main>
</div>

    <!-- 依赖库 手机调试的js引用顺序如下 -->
    <script src="js/zepto.js"></script>
    <script src="js/plugins/fastclick.js"></script>
    <script src="js/bui.js"></script>
    <script src="js/common.js?00    "></script>
    <script>
        bui.ready(function () {
            // 这里写业务及控件初始化
            initCommon(bui,"0");
            var yhbm = $$("yhbm");
            var lx = $$("lx");
            // if(yhbm && yhbm != null && yhbm != ""){
            //     bui.load({ url: "./pages/home.html"});
            //     // if(lx == 1){
            //     //     bui.load({ url: "./pages/home.html"});
            //     // }else if(lx == 2){
            //     //     bui.load({ url: "./pages/home.html"});
            //     // }
            // }
            bui.btn({id: ".bui-page", handle: ".bui-btn"}).load();
            var pageview = {};
            pageview.init = function () {
                // 验证码示例
                var $btnSend = $("#btnSend");
                var timer = bui.timer({
                    onEnd: function () {
                        $btnSend.removeClass("disabled").text("重新获取验证码");
                    },
                    onProcess: function (e) {
                        var valWithZero = e.count < 60 ? "0" + e.count : e.count;
                        $btnSend.text(valWithZero + "后重新获取");
                    },
                    times: 60
                });

                $("#login").on("click", function (argument) {
                    var phone = $("#phone").val();
                    if($.trim(phone) == ""){
                        bui.alert("手机号不能为空");
                        return ;
                    }
                    var code = $("#code").val();
                    if($.trim(code) == ""){
                        bui.alert("验证码为空");
                        return ;
                    }
                    //执行登录操作
                    var loginAjax = bui.ajax({
                        url: BASE_URL+"/front/login",
                        // 可选参数
                        data: {
                            phone:phone,
                            code:code
                        },
                        method: "POST"
                    });

                    loginAjax.then(function(res) {
                        if(res.code == 0){
                            var user = res.data;
                            if(user){
                                var storage = bui.storage();
                                var token = user.token;
                                storage.set("yhbm",user.yhbm);
                                storage.set("mobile",user.mobile);
                                storage.set("user",user);
                                storage.set("membercode",user.membercode);
                                storage.set("subno",user.subno);
                                storage.set("token",token);
                                storage.set("lx",user.lx);
                                $.cookie("mobile", user.mobile, { expires: 7 });
                                $.cookie("mm", mm, { expires: 7 });
                                bui.alert("登录成功");
                                TOKEN = token;
                                bui.config.ajax = {
                                    headers: {
                                        token:token
                                    }
                                };
                                var lx  = user.lx;
                                if(lx > 0 ){
                                    bui.load({ url: "./pages/home.html"});
                                }else{
                                    bui.alert("用户类型错误");
                                }
                            }
                        }else{
                            bui.alert(res.msg);
                        }
                    },function(res) {
                        bui.alert("请求异常");
                    })


                });
                $btnSend.on("click", function (argument) {
                    var phone = $("#phone").val();
                    if($.trim(phone) == ""){
                        bui.alert("手机号不能为空");
                        return ;
                    }
                    var hasDisabled = $(this).hasClass("disabled");
                    if (!hasDisabled) {
                        var data = {
                            phone:phone
                        }
                        var codeAjax = bui.ajax({
                            url: BASE_URL+"/front/sendValidCode",
                            // 可选参数
                            data:data,
                            method: "GET"
                        });
                        codeAjax.then(function(res) {
                            if(res.code == 0){
                                $(this).addClass("disabled")
                                bui.hint("验证码发送成功")
                                timer.restart();
                            }else{
                                bui.alert(res.msg);
                            }
                        },function(res) {
                            bui.alert("请求异常");
                        })
                    }
                })

            }
            pageview.init();
        })
    </script>
</body>
</html>